package io.dshubs.archives.controller;


import io.dshubs.archives.entity.ArchiveAppraisal;
import io.dshubs.archives.entity.ArchiveReorginze;
import io.dshubs.archives.service.ArchiveAppraisalService;
import io.dshubs.archives.service.ArchiveReorginzeService;
import io.dshubs.commons.log.annotation.LogOperation;
import io.dshubs.commons.tools.constant.Constant;
import io.dshubs.commons.tools.exception.RenException;
import io.dshubs.commons.tools.page.PageData;
import io.dshubs.commons.tools.utils.Result;
import io.dshubs.commons.tools.validator.ValidatorUtils;
import io.dshubs.commons.tools.validator.group.AddGroup;
import io.dshubs.commons.tools.validator.group.DefaultGroup;
import io.dshubs.commons.tools.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  收集整编
 * </p>
 *
 * @author zhang
 * @since 2021-09-02
 */
@Api(tags = "收集整编")
@RestController
@RequestMapping("/reorginze")
@AllArgsConstructor
public class ArchiveReorginzeController {

    ArchiveReorginzeService reorginzeService;

    @GetMapping("page")
    @ApiOperation("page")
    @LogOperation("收集整编:/archive/appraisal:/img/icon-收集整编.png:page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String") ,
            @ApiImplicitParam(name = "appraisalTitle", value = "题名", paramType = "query", dataType="String"),
            @ApiImplicitParam(name = "fileNumber", value = "档号", paramType = "query", dataType="String")
    })

    public Result<PageData<ArchiveReorginze>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        return new Result<PageData<ArchiveReorginze>>().ok(reorginzeService.page(params));
    }

    @GetMapping("{id}")
    @ApiOperation("详情")
    @LogOperation("收集整编:archive/appraisal:/img/icon-收集整编.png:get")
    public Result<ArchiveReorginze> get(@PathVariable("id") Long id){
        return new Result<ArchiveReorginze>().ok(reorginzeService.selectById(id));
    }

    @GetMapping("/form/{formKey}")
    @ApiOperation("获取表单信息")
    @LogOperation("自定义表单:select")
    public Result<String> getFormData(@PathVariable("formKey") String formKey){
        return new Result<String>().ok(reorginzeService.getFormData(formKey));
    }

    @GetMapping("/form/list/all")
    @ApiOperation("获取所有表单")
    @LogOperation("自定义表单:select")
    public Result<List<String>> getFormDataList(){
        return new Result<List<String>>().ok(reorginzeService.getFormDataList());
    }

    @PostMapping
    @ApiOperation("保存")
    @LogOperation("收集整编:save")
    public Result save(@RequestBody ArchiveReorginze archiveReorginze){
        reorginzeService.insert(archiveReorginze);
        return new Result();
    }

    @PutMapping
    @ApiOperation("修改")
    @LogOperation("收集整编:update")
    public Result update(@RequestBody ArchiveReorginze archiveReorginze){
        reorginzeService.updateById(archiveReorginze);
        return new Result();
    }

    @DeleteMapping
    @ApiOperation("删除")
    @LogOperation("收集整编:delete")
    public Result delete(@RequestBody @NotNull(message = "批量删除id不能为空") List<Long> ids){
        reorginzeService.deleteBatchIds(ids);
        return new Result();
    }


    @PutMapping("/authenticated")
    @LogOperation("收集整编:reorginze")
    public Result reorginze(@RequestBody @NotNull(message = "鉴定id不能为空") ArchiveReorginze archiveReorginze){
        return new Result();
    }
}
